package com.etop.ondoc.dao;


import org.hibernate.Session;

import com.etop.ondoc.beans.*;
import com.etop.ondoc.util.HibernateUtil;
import com.github.cuter44.nyafx.dao.DaoBase;
public class BCategoryDao extends DaoBase<Category>{
/*	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");*/	
	public BCategoryDao(){
		super();
	}
	  // SINGLETON
    private static class Singleton
    {
        public static BCategoryDao instance = new BCategoryDao();
    }

    public static BCategoryDao getInstance()
    {
        return(Singleton.instance);
    }
	@Override
	protected Class classOfT() {
		return Category.class;
	}
	public Category create(String name){
		Category cate = new Category();
		cate.setName(name);
		this.save(cate);
		this.close();
		return (cate);
	}
	public void add(Category c){
		if(c!=null){
			try {
				this.begin();
				this.save(c);
				this.commit();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				this.close();
			}
		}
	}
	public Category load(int id) {
		Category c = null;
		try {
			this.begin();
	        c = (Category) this.get(Category.class, id);
	        this.close();
		}catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.close();
		}
        return c;
    }
}
